package com.eschool.beans;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import com.eschool.model.Room;
import com.eschool.service.SchoolManagementService;
import com.eschool.service.impl.SchoolManagementServiceImpl;

@ManagedBean(name="roomBean")
@ViewScoped
public class RoomBean {
	
	Room room = new Room();
	SchoolManagementService service = new SchoolManagementServiceImpl();
	
	public Room getRoom() {
		return room;
	}

	public void setRoom(Room room) {
		this.room = room;
	}
	
	public String performAction()
	{
		String message;
		
		if(service.addRoom(room)) {
			message = "Room Successfully Added";
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Info Message", message));
		}
		else {
			message = "Room Not Added";
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error Message", message));
		}
		
		return "AddRoom";
	}

}
